<template>
  <div>
    <van-pull-refresh class="content" v-model="isLoading" @refresh="onRefresh">
      <div style="padding:40px 0 10px;background: #ccc;">
        <Logo></Logo> 
      </div>
      <van-collapse v-model="activeName" accordion>
        <van-collapse-item title="ppt模块" name="1">
          <van-cell-group>
            <van-cell @click="openPPTDetail()" title="PPT详情页" is-link />
          </van-cell-group>
          
        </van-collapse-item>
      </van-collapse>
      
    </van-pull-refresh>
    
    <van-tabbar v-model="active">
      <van-tabbar-item icon="home">主页</van-tabbar-item>
      <van-tabbar-item icon="chat" dot>消息</van-tabbar-item>
      <van-tabbar-item icon="records" info="5">记录</van-tabbar-item>
      <van-tabbar-item icon="gold-coin" info="20">哈哈</van-tabbar-item>
    </van-tabbar>
  </div>
</template>
<script>
import Vue from "vue";
import {
  openWebview,
  openWebviewFast,
  preLoad,
  showWebviewById
} from "@/utils/webview";
import { request, getaxios } from "@/utils/request";
import {
  Dialog,
  CellGroup,
  Toast,
  PullRefresh,
  Tabbar,
  TabbarItem,
  Cell,
  List,
  Actionsheet,
  NavBar,
  Tag,
  Collapse,
  CollapseItem
} from "vant";
import Logo from "./components/logo.vue";
export default {
  components: {
    Logo,
    [Dialog.name]: Dialog,
    [CellGroup.name]: CellGroup,
    [Toast.name]: Toast,
    [PullRefresh.name]: PullRefresh,
    [Tabbar.name]: Tabbar,
    [TabbarItem.name]: TabbarItem,
    [Cell.name]: Cell,
    [List.name]: List,
    [Actionsheet.name]: Actionsheet,
    [NavBar.name]: NavBar,
    [Tag.name]: Tag,
    [Collapse.name]: Collapse,
    [CollapseItem.name]: CollapseItem
  },
  created() {
    window.addEventListener("customEvent", function(event) {
      //通过event.detail可获得传递过来的参数内容
      plus.nativeUI.toast("我是首页,我很慌,我收到了信息");
      console.log(event.detail);
    });
    function plusReady() {
      let ws = plus.webview.currentWebview();
      console.log(ws);
    }
    if (window.plus) {
      plusReady();
    } else {
      document.addEventListener("plusready", plusReady, false);
    }

    // 预加载一些窗口
//  preLoad([
//    {
//      url: "./ppt.detail.html?token=MTE1MTQ4NTExMjg1MzQwNDU5Mg&id=1",
//      id: "ppt.detail",
//      title: "ppt详情页"
//    }
//  ]);
  },
  data() {
    return {
      activeName: "1",
      count: 0,
      isLoading: false,
      active: 0,
      list: [],
      loading: false,
      finished: false,
      show: false
    };
  },

  methods: {
    // 使用预加载速度会很快,但是没法再次传值,只能通过页面之间的通讯完成传值,参考goods.detail页面中的fire
    openPPTDetail(){
//  	预加载后打开
//  	showWebviewById("ppt.detail");

//		打开
//  	openWebview({
//    	id:"goods.detail",
//    	url:"./ppt.detail.html?token=MTE1MTQ4NTExMjg1MzQwNDU5Mg&id=1"
//    });
      
      openWebviewFast(
      	"./ppt.detail.html?token=MTE1MTQ4NTExMjg1MzQwNDU5Mg&id=2",
      	"goods.detail"
      );
    },
    onRefresh() {
      this.isLoading = true;
      console.log(TESTAPI)
      getaxios(TESTAPI+"/ppt/queryById", { "id": 1,"token": "MTE1MTQ4NTExMjg1MzQwNDU5Mg"})
        .then(res => {
        	console.log(res)
          this.isLoading = false;
          plus.nativeUI.toast("Ajax请求成功");
          console.log(res);
        })
        .catch(err => {
          this.isLoading = false;
          console.error(err);
        });
    }
  }
};
</script>

<style lang="less">
:global {
  body {
  	background-color: #f8f8f8;
    -webkit-font-smoothing: antialiased;
    font-family: PingFang SC, Helvetica Neue, Arial, sans-serif;
  }
}

</style>
